package com.zky.gulimall.product;

import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/11/11 22:36
 * @Version 1.0
 **/
public class Interrupt {


    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println(Thread.currentThread().getName() + "\tisInterrupted()被修改为true,程序停止");
                    break;
                }
                System.out.println("t1-------hello volatile");
            }
        }, "t1");
        t1.start();

        try {
            TimeUnit.MILLISECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new Thread(() -> {
            t1.interrupt();
        }, "t2").start();
    }
}
